import React from "react";

class Comp2 extends React.Component {
  state = {
    image: "https://robohash.org/123?set=set5",
    price: 100,
    count: 2,
  };
  render() {
    const { image, price, count } = this.state;
    return (
      <div>
        <div>
          <img src={image} alt="" />
          <div>单价：{price}</div>
          <div>
            <button onClick={() => this.setState({ count: count - 1 })}>
              -
            </button>
            <span>{count}</span>
            <button onClick={() => this.setState({ count: count + 1 })}>
              +
            </button>
          </div>
          <div>小记： {price * count}</div>
        </div>
      </div>
    );
  }
  shouldComponentUpdate(nextProps, nextState) {
    if (nextState.count > 5) return false;
    if (nextState.count < 1) return false;
    return true;
  }
}

export default Comp2;
